//
//  COFoodCollectionViewCell.swift
//  CocoProject
//
//  Created by Ruthless on 2023/8/20.
//

import UIKit

class COFoodCollectionViewCell: UICollectionViewCell {
    var model: FoodType? {
        didSet {
            guard let model = model else {
                return
            }
            
            nameLabel.text = model.name
            foodImageView.image = UIImage(named: "food\(model.rawValue)")
        }
    }
    override init(frame: CGRect) {
        super.init(frame: frame)
        
        configUI()
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    private func configUI() {
        backgroundColor = .rgba(17, 7, 41)
        contentView.addSubview(mainView)
        contentView.addSubview(foodImageView)
        contentView.addSubview(nameLabel)
        contentView.addSubview(totalLabel)
        
        mainView.snp.makeConstraints { make in
            make.edges.equalToSuperview()
        }
        
        foodImageView.snp.makeConstraints { make in
            make.centerX.equalToSuperview()
            make.top.equalTo(mainView.snp.top).offset(19)
            make.width.height.equalTo(60)
        }
        
        nameLabel.snp.makeConstraints { make in
            make.centerX.equalToSuperview()
            make.bottom.equalTo(totalLabel.snp.top).offset(-5)
        }
        
        totalLabel.snp.makeConstraints { make in
            make.centerX.equalToSuperview()
            make.bottom.equalToSuperview().offset(-15)
        }
    }
    
    
    private lazy var mainView: UIButton = {
        let btn = UIButton()
        btn.setImage(UIImage(named: "编组 8"), for: .normal)
        btn.setImage(UIImage(named: "编组 18"), for: .selected)
        btn.isUserInteractionEnabled = false
        return btn
    }()
    
    private lazy var foodImageView: UIImageView = {
        let imgV = UIImageView()
        return imgV
    }()
    
    private lazy var nameLabel: UILabel = {
        let label = UILabel()
        label.font = .bold(17)
        label.textColor = .white
        return label
    }()
    
    private(set) lazy var totalLabel: UILabel = {
        let label = UILabel()
        label.font = .medium(13)
        label.textColor = .white.withAlphaComponent(0.3)
        return label
    }()
}
